#include "photoshow.h"
#include "ui_photoshow.h"

PhotoShow::PhotoShow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PhotoShow)
{
    ui->setupUi(this);

    //去掉标题栏
    this->setWindowFlags(Qt::FramelessWindowHint);

    // 定义最小化和返回按键
    connect(ui->btnWinClose, &QPushButton::clicked,   this, [=](){ this->close(); });
    connect(ui->btnWinMin, &QPushButton::clicked,     this, [=](){ this->showMinimized(); });
}

/**
 * @brief 显示图片
 * @param img 输入的图片
 */
void PhotoShow::ShowImg(QIcon ico)
{
    QPixmap pix = ico.pixmap(ui->labelImg->size());
    QPixmap des = pix.scaled(ui->labelImg->size());
    ui->labelImg->setPixmap(des);

    this->show();
}

PhotoShow::~PhotoShow()
{
    delete ui;
}

// 重定义鼠标移动函数
void PhotoShow::mousePressEvent(QMouseEvent *e)
{
    last=e->globalPos();
}
void PhotoShow::mouseMoveEvent(QMouseEvent *e)
{
    int dx = e->globalX() - last.x();
        int dy = e->globalY() - last.y();
        last = e->globalPos();
        move(x()+dx, y()+dy);
}
void PhotoShow::mouseReleaseEvent(QMouseEvent *e)
{
    int dx = e->globalX() - last.x();
    int dy = e->globalY() - last.y();
    move(x()+dx, y()+dy);
}
